#include "avr/io.h"
#include "avr/interrupt.h"

volatile uint8_t i = 0;

ISR (TIMER0_COMPA_vect)
{
	i++;
	// 5 udaa 200 millisekunden = 1 sekund
	if (i == 5) {
		// LED g untraastai bol asaa, asaalttai bol untraa
		PORTB ^= (1 << PB1);
		i = 0;
	}	
}

int main() {
	// PB1 hol deer LED zalgagdsan
	DDRB |= (1 << PB1);
	// LED g asaa
	PORTB |= (1 << PB1);

	// Tooluuriin utgiig 0 bolgo
	TCNT0 = 0;
	// tooluuriin utga OCR0A tai tentsvel tooluuriig tegle
	TCCR0A |= (1 << WGM01);
	// mikrocontroller 1000000 herz iin hurdtai ajillaj baigaa
	// 1/(1000000/1024) = 0,001024 sekund
	// tooluuriin utga 1,024 millisekund bolgond 1 eer nemegdene
	TCCR0B |= (1 << CS02) | (1 << CS00);
	// 200 millisekund tutamt compare match interrupt uusne
	OCR0A = 199;
	// compare match interrupt iig uusehiig zovshooroh
	TIMSK |= (1 << OCIE0A);
	// global interrupt zovshooroh
	sei();
	while(1) {
		// end oor uildel hiij bolno
	}
	return 0;
}
